/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package foalvleditor.gameobjects;

import java.awt.Graphics;
import java.awt.Transparency;
import java.awt.image.BufferedImage;
import javax.swing.ImageIcon;
import javax.swing.JOptionPane;

/**
 * Mockup android bitmap class
 * @author Mikael
 */

public class Bitmap implements Cloneable {

    private String bitmapCode;
    private transient BufferedImage bufImg;
    private transient int height;
    private transient int width;
    private static org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(foalvleditor.core.FoaLvlEditorApp.class).getContext().getResourceMap(Bitmap.class);
    

public Bitmap(String str){
    this.bitmapCode=str;
    loadBitmap();
    }

    public final void loadBitmap(){
    try{
        ImageIcon img;
        img=resourceMap.getImageIcon(bitmapCode);
        this.height=img.getIconHeight();
        this.width=img.getIconWidth();
        BufferedImage newImage=new BufferedImage(width, height, Transparency.TRANSLUCENT);
        this.setBufferedImage(newImage);
        Graphics gx=bufImg.createGraphics();
        gx.drawImage(img.getImage(), 0, 0, null);
        gx.dispose();
    }
        catch (Exception e){
            JOptionPane.showMessageDialog(null, "Error while processing images.");
    }
    }

    private void setBufferedImage(BufferedImage bufImg){
        this.bufImg=bufImg;
    }

    public BufferedImage getBufferedImage(){
        return this.bufImg;
    }

    public void setBitmapCode(String fileName){
        this.bitmapCode=fileName;
        loadBitmap();
    }

    public String getBitmapCode(){
        if (bitmapCode==null)
        {
            return "";
        }
        return bitmapCode;
    }

    public int getHeight(){
        return this.height;
    }

    public int getWidth(){
        return this.width;
    }

    @Override
        public Bitmap clone() throws CloneNotSupportedException{
            return (Bitmap) super.clone();
        }
}